
  function digui (arr) {
    if (!arr || arr.length == 0) {
      return null;
    }
    if (arr.length == 1) {
      return arr;
    }

    let n = Math.floor(arr.length / 2);

    let left = arr.slice(0, n);

    let right = arr.slice(n, arr.length);

    let leftArr = digui(left);

    let rightArr = digui(right);

    let temArr = new Array(leftArr.length + rightArr.length);
    let i = 0;
    let j = 0;
    let k = 0;
    while (k < temArr.length) {
      if(i>=leftArr.length){
        temArr[k] = rightArr[j];
        j++;
      }else if(j>=rightArr.length){
        temArr[k] = leftArr[i];
        i++;
      }else if (leftArr[i] <= rightArr[j]) {
        temArr[k] = leftArr[i];
        i++;
      } else {
        temArr[k] = rightArr[j];
        j++;
      }
      k++
    }
    return temArr
  }


console.log(digui([9,8,7,6,5,4,3,2,1,0]),'log');

